﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;
using PBOffice.Models;

namespace PBOffice.DAL
{
    public class PreContractService
    {
        public List<PreContract> GetPreContractByScheduleId(int id)
        {
            string sql = string.Format("select s.*,p.* from Schedule s,PreContract p where s.ScheduleId=p.ScheduleId and p.ScheduleId={0}", id);
            List<PreContract> list = new List<PreContract>();
            using (SqlDataReader dr = SqlHelp.ExecuteReader(SqlHelp.connectionstring, CommandType.Text, sql))
            {
                while (dr.Read())
                {
                    Schedule sch = new Schedule();
                    sch.ScheduleId = (int)dr["ScheduleId"];
                    PreContract pre = new PreContract();
                    pre.PreContractId = (int)dr["PreContractId"];
                    pre.UserId = dr["UserId"].ToString();
                    pre.schedule = sch;
                    list.Add(pre);
                }
            }
            return list;

        }
        public void DeletePreContract(int id)
        {
            string sql = string.Format("delete [PreContract] where PreContractId={0}", id);
            SqlHelp.ExecuteNonQuery(SqlHelp.connectionstring, CommandType.Text, sql);
        }
    }
}
